package com.charmpeach.tsss;


import org.apache.http.impl.client.DefaultHttpClient;

import com.charmpeach.tsss.crawler.CourseTag;
import com.charmpeach.tsss.crawler.MessageManger;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.widget.TextView;

public class Announcement extends Activity {
	DefaultHttpClient client = null;
	String sessionID = null;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.announcement_layout);
        Intent intent = getIntent();
        final CourseTag tag = new CourseTag(intent.getStringExtra("tag"));
        final Handler handler = new Handler()
		{

			public void handleMessage(Message message)
			{
				System.out.println(message.obj.toString());
				String tmp[] = ((String) message.obj).split("\\$");
				
				TextView title = (TextView)findViewById(R.id.announcement_TitleContent);
				TextView date = (TextView)findViewById(R.id.announcement_dateContent);
				TextView des = (TextView)findViewById(R.id.announcement_descriptionContent);
				
				des.setText(Html.fromHtml(tmp[2]));
				title.setText(tmp[1]);
				date.setText(tmp[0]);
			}
		};
		
		Thread thread = new Thread()
		{
			public void run()
			{
				MessageManger mm = MessageManger.getInstance();
				String temp=null;
				try {
					temp = mm.getAnnouncementDetail(tag.getCouserID(), tag.getMessage(),Announcement.this);
				} catch (Exception e) {
					// TODO: handle exception
				}
				if(temp == null)
					return;
				Message message = handler.obtainMessage(1, temp);
				handler.sendMessage(message);
			}
			
		};
		
		thread.start();
    }

}
